//
//  HWChangeSegmentView.m
//  嗨文
//
//  Created by 响当当 on 2019/2/13.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWChangeSegmentView.h"

@interface HWChangeSegmentView()
/*
 阅读口味
*/
@property (nonatomic, strong)UIButton *boyBookBtn;//男生小说
@property (nonatomic, strong)UIButton *girlBookBtn;//女生小说
@end

@implementation HWChangeSegmentView

- (UIButton *)boyBookBtn
{
    if (!_boyBookBtn)
    {
        _boyBookBtn = [HWUtilties creatButtonWithFrame:CGRectMake(68*kUIScaleBasePlus,75*kUIScaleBasePlus,240*kUIScaleBasePlus,72*kUIScaleBasePlus)
                                          textAligment:NSTextAlignmentLeft
                                                  text:@""
                                              textClor:nil
                                             buttonBGC:[UIColor clearColor]
                                              textFont:0
                                                target:self
                                                method:@selector(boyAndGirlBookClick:)];
        _boyBookBtn.tag = 0;
        [_boyBookBtn setBackgroundImage:[UIImage imageNamed:@"male_normal"] forState:UIControlStateNormal];
    }
    return _boyBookBtn;
}

- (UIButton *)girlBookBtn
{
    if (!_girlBookBtn)
    {
        _girlBookBtn = [HWUtilties creatButtonWithFrame:CGRectMake(68*kUIScaleBasePlus,CGRectGetMaxY(self.boyBookBtn.frame)+25*kUIScaleBasePlus,240*kUIScaleBasePlus,72*kUIScaleBasePlus)
                                          textAligment:NSTextAlignmentLeft
                                                  text:@""
                                              textClor:nil
                                             buttonBGC:[UIColor clearColor]
                                              textFont:0
                                                target:self
                                                 method:@selector(boyAndGirlBookClick:)];
        _girlBookBtn.tag = 1;
        [_girlBookBtn setBackgroundImage:[UIImage imageNamed:@"female_normal"] forState:UIControlStateNormal];
    }
    return _girlBookBtn;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self addSubview:self.boyBookBtn];
        [self addSubview:self.girlBookBtn];
    }
    return self;
}

- (void)boyAndGirlBookClick:(UIButton *)sender
{
    NSInteger tag = sender.tag;
    if (self.segemtChangeBlock)
    {
        self.segemtChangeBlock(tag);
    }
    
    if (tag == 0)
    {
        [_boyBookBtn setBackgroundImage:[UIImage imageNamed:@"male_selected"] forState:UIControlStateNormal];
        [_girlBookBtn setBackgroundImage:[UIImage imageNamed:@"female_normal"] forState:UIControlStateNormal];
    }
    else
    {
        [_boyBookBtn setBackgroundImage:[UIImage imageNamed:@"male_normal"] forState:UIControlStateNormal];
        [_girlBookBtn setBackgroundImage:[UIImage imageNamed:@"female_selected"] forState:UIControlStateNormal];
    }
}
@end


/*
    男生小说
 */
@interface HWBoyBookView()

@end

@implementation HWBoyBookView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        
    }
    return self;
}

//Creat UI
- (void)creatUI:(NSArray *)arr
{
    CGFloat width = 90*kUIScaleBasePlus;
    CGFloat height = 37*kUIScaleBasePlus;
    
    for (int i=0; i< arr.count; i++)
    {
        UIButton *btn = [HWUtilties creatButtonWithFrame:CGRectMake(37*kUIScaleBasePlus+(width+15*kUIScaleBasePlus)*(i%3),47*kUIScaleBasePlus+(height+15*kUIScaleBasePlus)*(i/3),width,height)
                                            textAligment:NSTextAlignmentCenter
                                                    text:arr[i][@"seriesName"]
                                                textClor:LCHexColor(0x363B43)
                                               buttonBGC:LCHexColor(0xF5F8FB)
                                                textFont:13*kUIScaleBasePlus
                                                  target:self
                                                  method:@selector(boyBookClick:)];
        btn.selected = NO;
        NSNumber *num = IFNULL(arr[i][@"seriesId"], [NSNumber new]);
        btn.tag = [num integerValue];
        [self addSubview:btn];
    }
    
}

- (void)boyBookClick:(UIButton *)sender
{
    
    if (!sender.selected)
    {
        [sender setBackgroundColor:LCHexColor(0xFFF5F5)];
        [sender setTitleColor:LCHexColor(0xF54337) forState:UIControlStateNormal];
        sender.selected = YES;
    }
    else
    {
        [sender setBackgroundColor:LCHexColor(0xF5F8FB)];
        [sender setTitleColor:LCHexColor(0x363B43) forState:UIControlStateNormal];
        sender.selected = NO;
    }
    
    if (self.boyHabitNumBlock)
    {
        self.boyHabitNumBlock(sender.tag);
    }
}
@end

/*
 女生小说
 */
@interface HWGirlBookView()

@end

@implementation HWGirlBookView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        
    }
    return self;
}

//Creat UI
- (void)creatUI:(NSArray *)arr
{
    CGFloat width = 90*kUIScaleBasePlus;
    CGFloat height = 37*kUIScaleBasePlus;
    
    for (int i=0; i< arr.count; i++)
    {
        UIButton *btn = [HWUtilties creatButtonWithFrame:CGRectMake(37*kUIScaleBasePlus+(width+15*kUIScaleBasePlus)*(i%3),47*kUIScaleBasePlus+(height+15*kUIScaleBasePlus)*(i/3),width,height)
                                            textAligment:NSTextAlignmentCenter
                                                    text:arr[i][@"seriesName"]
                                                textClor:LCHexColor(0x363B43)
                                               buttonBGC:LCHexColor(0xF5F8FB)
                                                textFont:13*kUIScaleBasePlus
                                                  target:self
                                                  method:@selector(girlBookClick:)];
        btn.selected = NO;
        NSNumber *num = IFNULL(arr[i][@"seriesId"], [NSNumber new]);
        btn.tag = [num integerValue];
        [self addSubview:btn];
    }
    
}
- (void)girlBookClick:(UIButton *)sender
{
    if (!sender.selected)
    {
        [sender setBackgroundColor:LCHexColor(0xFFF5F5)];
        [sender setTitleColor:LCHexColor(0xF54337) forState:UIControlStateNormal];
        sender.selected = YES;
    }
    else
    {
        [sender setBackgroundColor:LCHexColor(0xF5F8FB)];
        [sender setTitleColor:LCHexColor(0x363B43) forState:UIControlStateNormal];
        sender.selected = NO;
    }
    
    if (self.girlHabitNumBlock)
    {
        self.girlHabitNumBlock(sender.tag);
    }
}
@end
